//
//  RightsManageCell.m
//  StarOrangeStaff
//
//  Created by lshenrong on 2020/7/1.
//  Copyright © 2020 lshenrong. All rights reserved.
//

#import "RightsManageCell.h"

@interface RightsManageCell ()

@property (nonatomic,strong) UILabel *titleLbl;
@property (nonatomic,strong) UISwitch *switchView;

@end

@implementation RightsManageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self!=nil){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.titleLbl];
        [self.contentView addSubview:self.switchView];
        
        [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView).mas_offset(kMarginOffsetX);
            make.centerY.mas_equalTo(self.contentView);
        }];
        [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).mas_offset(-kMarginOffsetX);
            make.centerY.mas_equalTo(self.contentView);
        }];
    }
    return self;
}

- (void)updateTitle:(NSString *)title setOn:(BOOL)isOn{
    self.titleLbl.text = title;
    if(isOn!=self.switchView.isOn){
        [self.switchView setOn:isOn animated:YES];
    }
}

- (void)updateTitle:(NSString *)title{
    self.titleLbl.text = title;
}

- (void)switchAction:(UISwitch *)sender{
    if(self.switchBlock){
        self.switchBlock(sender);
    }
}

- (UISwitch *)switchView{
    if (!_switchView) {
        _switchView =  [[UISwitch alloc]init];
        _switchView.onTintColor =  kBlueColor;
        [_switchView setOn:YES animated:NO];
        [_switchView addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    }
    return _switchView;
}


MACRO_UILabelWithPFCGFont(titleLbl, @"权限标题",kBlackColor, 14)

@end
